package com.scnlf.scnlf.portal.core.business.loan.service.impl;

import com.scnlf.scnlf.portal.core.business.loan.entity.LoanPositionEntity;
import com.scnlf.scnlf.portal.core.business.loan.repo.LoanPositionRepo;
import com.scnlf.scnlf.portal.core.business.loan.service.ILoanPositionService;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class LoanPositionServiceImpl implements ILoanPositionService {

  private final LoanPositionRepo loanPositionRepo;

  @Override
  public LoanPositionEntity insertLoanPosition(LoanPositionEntity loanPosition) {
    loanPosition.setAllowBuyQty(Optional.ofNullable(loanPosition.getAllowBuyQty()).orElse(0L));
    loanPosition.setAllowSellingQty(Optional.ofNullable(loanPosition.getAllowSellingQty()).orElse(0L));
    return loanPositionRepo.save(loanPosition);
  }

  @Override
  public LoanPositionEntity getLoanPosition(String customerNo, String symbol) {
    return loanPositionRepo.findByCustomerNoAndSymbol(customerNo, symbol);
  }

}
